package kr.hkit.androidcomplete02.ch11;

import kr.hkit.androidcomplete02.R;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.ToggleButton;

public class RadioCheck extends Activity {
	TextView mText;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch11_radiocheck);

		mText = (TextView) findViewById(R.id.ch11_radiocheck_tv);

		RadioGroup colGroup = (RadioGroup) findViewById(R.id.ch11_colorgroup);
		colGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				if (group.getId() == R.id.ch11_colorgroup) {
					switch (checkedId) {
					case R.id.ch11_rared:
						mText.setTextColor(Color.RED);
						break;
					case R.id.ch11_ragreen:
						mText.setTextColor(Color.GREEN);
						break;
					case R.id.ch11_rablue:
						mText.setTextColor(Color.BLUE);
						break;
					}
				}
			}
		});

		CheckBox chkWhite = (CheckBox) findViewById(R.id.ch11_chkwhiteback);
		chkWhite.setOnCheckedChangeListener(mListener);

		ToggleButton tgLang = (ToggleButton) findViewById(R.id.ch11_tglanguage);
		tgLang.setOnCheckedChangeListener(mListener);
	}

	CompoundButton.OnCheckedChangeListener mListener = new CompoundButton.OnCheckedChangeListener() {
		public void onCheckedChanged(CompoundButton buttonView,
				boolean isChecked) {
			if (buttonView.getId() == R.id.ch11_chkwhiteback) {
				if (isChecked) {
					mText.setBackgroundColor(Color.BLACK);
				} else {
					mText.setBackgroundColor(Color.TRANSPARENT);
				}
			}
			if (buttonView.getId() == R.id.ch11_tglanguage) {
				if (isChecked) {
					mText.setText("샘플");
				} else {
					mText.setText("Sample");
				}
			}
		}
	};
}
